﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Sql;
using System.Data.SqlClient;

namespace KaoWuYou.Models
{
    public class SubjectListModel
    {
        public List<SubjectModel> Subjects
        { set; get; }

        public void FindAllSubjects()
        {
            this.Subjects = new List<SubjectModel>();

            SqlConnection conn = new SqlConnection(Systems.ConnString);
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT * FROM Subject";
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.NextResult())
            {
                SubjectModel tmp = new SubjectModel()
                {
                    SubjectID = (int)sdr["SubjectID"],
                    SubjectName = sdr["SubjectName"] as string                    
                };
                tmp.GetOwnedSubclasses();
                this.Subjects.Add(tmp);
            }
            sdr.Close();
            conn.Close();

           

        }
    }
}